package cn.liujianbo.example.convertor;

/**
 * @author 刘建波
 * @date 2021-10-14 21:49
 */

import cn.liujianbo.example.domain.Car;
import cn.liujianbo.example.dto.CarDto;
import org.mapstruct.*;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper
public interface CarConvertor {

    CarConvertor INSTANCE = Mappers.getMapper(CarConvertor.class);

    @Mappings({
            @Mapping(source = "make", target = "make"),
            @Mapping(source = "numberOfSeats", target = "seatCount"),
            @Mapping(target = "type", expression = "java(car.getType().getTypeName())")
    })
    CarDto carToCarDto(Car car);

    List<CarDto> carToCarDtos(List<Car> cars);

    @InheritInverseConfiguration(name = "carToCarDto")
    @Mapping(target = "type", ignore = true)
    Car carDtoToCar(CarDto carDto);

    List<Car> carDtoToCars(List<CarDto> carDtos);
}
